package singleton;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.thread.ThreadUtil;

import java.util.Objects;

/**
 * @Author: 582895699@qq.com
 * @Desctription: TODO
 * @Date: Created in 2021/12/7 21:04
 */
public class SingletonThree {
    private static volatile SingletonThree SINGLETON_THREE = null;

    private SingletonThree() {
        System.out.println("加载");
    }


    public static SingletonThree getInstance() {
        // 第一次判空
        if (Objects.isNull(SINGLETON_THREE)) {
            // 在懒汉式（线程安全）的基础上缩小了锁定代码快的范围
            synchronized (SingletonThree.class) {
                // 第二次判空
                if (Objects.isNull(SINGLETON_THREE)) {
                    SINGLETON_THREE = new SingletonThree();
                }
            }
        }
        return SINGLETON_THREE;
    }

    public String getDate() {
        return DateUtil.now();
    }

}
